<template>
  <div class="classification">
    <div class="el-row">
      <!-- 左侧导航栏 -->
      <div class="el-col-4 navigation">
        <div id="side-bar" class="side-bar affix-top">
          <ul>
            <li v-for="(od,index) in onedata.data" :key="od.id" class="side-text">
              <a @click="goAnchor('#productCategory_'+index)">
                <i class="iconfont text-blue" ></i>
                {{ od.name }}
              </a>
            </li>
          </ul>
        </div>
      </div>
      <!-- 分类 -->
      <div class="el-col-20 context">
        <!-- 抬头 -->
        <el-breadcrumb separator-class="el-icon-arrow-right" class="context-crumb">
          <el-breadcrumb-item to="/"><i class="el-icon-s-home"></i>首页</el-breadcrumb-item>
          <el-breadcrumb-item><span style="color: #409EFF !important;">商品分类</span></el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 内容 -->
        <div :id="'#productCategory_'+index" class="context-panel" v-for="(td,index) in threedata.data" :key="td.id">
          <div class="panel-heading">
            <h5>
              <a class="text-blue">{{ td.name }}</a>
            </h5>
          </div>
          <div class="panel-body">
            <div class="panel-child">
              <dl class="child-horizontal" v-for="child in td.children" :key="child.id">
                <dt>
                  <a class="text-blue-light" @click="gosearch(child.name)">
                    {{child.name}}
                    <i class="el-icon-arrow-right"></i>
                  </a>
                </dt>
                <dd>
                  <ul class="child-class clearfix" >
                    <li v-for="children in child.children" :key="children.id">
                      <a @click="gosearch(children.name)">{{ children.name }}</a>
                    </li>
                  </ul>
                </dd>
              </dl>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { three,one } from '@/api/classification'
import { ref } from "vue";
import { useStore } from "vuex";
import router from '@/router'

export default{
  name:'classification',
  setup(){
    
    let onedata = ref([])
    let threedata = ref([])

    function getonedata(){
      one().then(response =>{
        onedata.value = response.data
        // console.log(response.data)
        // console.log(onedata.value)
      })
    }
    function getthreedata(){
      three().then(response =>{
        threedata.value = response.data
        // console.log(response.data)
      })
    }
    function goAnchor(key){
      document.getElementById(key).scrollIntoView()
    }
    let store = useStore()
    // 二级标签和三级标签跳转按钮出发时间
    
    function gosearch(value){
      store.commit('setsearch',value)
      router.push({path:'/blank', query:{url:'/searchshop'}})
    }

    getonedata()
    getthreedata()
    
    return {
      gosearch,
      onedata,
      threedata,
      goAnchor,
    }
  },
}
</script>

<style scoped>
  *{
    font-size: 13px;
    color: #333;
  }
  a{
    text-decoration: none;
    color: #666666;
  }
  a:hover{
    text-decoration: none;
    cursor: pointer;
  }
  ul,li{
    list-style: none;
    padding: 0;
    margin: 0;
  }
  .text-blue{
    color: #5762fe;
  }
  .text-blue-light{
    color: #747dfe;
  }
  /* 整体 */
  .classification{
    height: 2400px;
    width: 1350px;
    display: block;
    margin: 15px auto 0;
  }
  /* 左侧导航栏 */

  .side-bar{
    width: 205px;
    background-color: #ffffff;
  }
  .side-text{
    padding: 10px 18px;
    margin-bottom: 15px;
    border-radius: 5px;
    font-size: 14px !important;
    background-color: #f5f5f5;
    position: relative;
  }
  .side-text:hover{
    background:-webkit-linear-gradient(left, rgba(87,98,257,0.8), rgba(103,160,225,0.8));
    cursor: pointer;
  }
  .side-text:hover a,.side-text:hover a i{
    color: white !important;
  }
  /* 分类详情 */
  .context-crumb{
    padding: 9px 15px;
    margin-bottom: 17px;
    border: 1px #eeeeee solid;
    background-color: #ffffff;
    border-radius: 0;
  }
  .context-panel{
    margin-bottom: 5px;
    border: none;
    background-color: white;
    box-shadow: none;
    border-radius: 4px;
  }
  /* 抬头 */
  .panel-heading{
    padding: 10px 0;
    border-bottom: 1px #5762fe solid;
  }
  .panel-heading h5{
    margin: 0;
  }
  .panel-heading h5 a{
    font-weight: bold;
  }
  .panel-heading h5 a:hover{
    color: #409EFF;
  }
  /* 内容 */
  .panel-body{
    padding: 0;
    margin-bottom: 17px;
  }
  .panel-child{
    padding: 0;
    margin: 5px auto;
  }
  .child-horizontal{
    height: 42px;
    border-bottom: 1px #eeeeee solid;
    margin: 0;
  }
  .child-horizontal dt{
    width: 127px;
    line-height: 42px;
    font-weight: normal;
    text-align: left;
    float: left;
    clear: left;
  }
  .child-horizontal dt a:hover,.child-class li a:hover{
    color: #409EFF;
  }
  .child-horizontal dd{
    line-height: 40px;
  }
  .child-class li{
    min-width: 80px;
    float: left;
    margin-right: 10px;
  }
</style>